package com.qiall.boot.fileservice.impl.fileuploadSuccessEvent;

import com.qiall.boot.fileservice.data.eitity.FileInfo;
import com.qiall.boot.fileservice.data.eitity.enums.UploadStatusEnum;
import com.qiall.boot.fileservice.data.mapper.FileInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

@Component
public class FileUploadSuccessListener {
    @Autowired
    private FileInfoMapper fileInfoMapper;

    @EventListener(classes = {UploadSuccessEvent.class})
    public void listener(UploadSuccessEvent uploadSuccessEvent) {
        FileInfo fileIno = new FileInfo();
        fileIno.setId(uploadSuccessEvent.getFileId());
        fileIno.setUploadStatus(UploadStatusEnum.已上传.getCode());
        fileIno.setFromId(uploadSuccessEvent.getFromId());
        fileInfoMapper.update(fileIno);
    }
}
